/***************************************************************************
 *   Copyright (C) 2009 by Borko Bošković                                  *
 *   borko.boskovic@gmail.com                                              *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#include <cstdlib>
#include <ctime>
#include "position.h"

#if __i386__
        #define UINT64(constantU64) constantU64##ULL
#elif __x86_64__
        #define UINT64(constantU64) constantU64
#endif

const int Position::magic_bb_r_shift[64] = {
    52, 53, 53, 53, 53, 53, 53, 52,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 54, 54, 54, 54, 53,
    53, 54, 54, 53, 53, 53, 53, 53
};

const Bitboard Position::magic_bb_r_magics[64] = {
    Bitboard(0x0080001020400080ull), Bitboard(0x0040001000200040ull),
    Bitboard(0x0080081000200080ull), Bitboard(0x0080040800100080ull),
    Bitboard(0x0080020400080080ull), Bitboard(0x0080010200040080ull),
    Bitboard(0x0080008001000200ull), Bitboard(0x0080002040800100ull),
    Bitboard(0x0000800020400080ull), Bitboard(0x0000400020005000ull),
    Bitboard(0x0000801000200080ull), Bitboard(0x0000800800100080ull),
    Bitboard(0x0000800400080080ull), Bitboard(0x0000800200040080ull),
    Bitboard(0x0000800100020080ull), Bitboard(0x0000800040800100ull),
    Bitboard(0x0000208000400080ull), Bitboard(0x0000404000201000ull),
    Bitboard(0x0000808010002000ull), Bitboard(0x0000808008001000ull),
    Bitboard(0x0000808004000800ull), Bitboard(0x0000808002000400ull),
    Bitboard(0x0000010100020004ull), Bitboard(0x0000020000408104ull),
    Bitboard(0x0000208080004000ull), Bitboard(0x0000200040005000ull),
    Bitboard(0x0000100080200080ull), Bitboard(0x0000080080100080ull),
    Bitboard(0x0000040080080080ull), Bitboard(0x0000020080040080ull),
    Bitboard(0x0000010080800200ull), Bitboard(0x0000800080004100ull),
    Bitboard(0x0000204000800080ull), Bitboard(0x0000200040401000ull),
    Bitboard(0x0000100080802000ull), Bitboard(0x0000080080801000ull),
    Bitboard(0x0000040080800800ull), Bitboard(0x0000020080800400ull),
    Bitboard(0x0000020001010004ull), Bitboard(0x0000800040800100ull),
    Bitboard(0x0000204000808000ull), Bitboard(0x0000200040008080ull),
    Bitboard(0x0000100020008080ull), Bitboard(0x0000080010008080ull),
    Bitboard(0x0000040008008080ull), Bitboard(0x0000020004008080ull),
    Bitboard(0x0000010002008080ull), Bitboard(0x0000004081020004ull),
    Bitboard(0x0000204000800080ull), Bitboard(0x0000200040008080ull),
    Bitboard(0x0000100020008080ull), Bitboard(0x0000080010008080ull),
    Bitboard(0x0000040008008080ull), Bitboard(0x0000020004008080ull),
    Bitboard(0x0000800100020080ull), Bitboard(0x0000800041000080ull),
    Bitboard(0x00FFFCDDFCED714Aull), Bitboard(0x007FFCDDFCED714Aull),
    Bitboard(0x003FFFCDFFD88096ull), Bitboard(0x0000040810002101ull),
    Bitboard(0x0001000204080011ull), Bitboard(0x0001000204000801ull),
    Bitboard(0x0001000082000401ull), Bitboard(0x0001FFFAABFAD1A2ull)
};

const Bitboard Position::magic_bb_r_mask[64] = {
    Bitboard(0x000101010101017Eull), Bitboard(0x000202020202027Cull),
    Bitboard(0x000404040404047Aull), Bitboard(0x0008080808080876ull),
    Bitboard(0x001010101010106Eull), Bitboard(0x002020202020205Eull),
    Bitboard(0x004040404040403Eull), Bitboard(0x008080808080807Eull),
    Bitboard(0x0001010101017E00ull), Bitboard(0x0002020202027C00ull),
    Bitboard(0x0004040404047A00ull), Bitboard(0x0008080808087600ull),
    Bitboard(0x0010101010106E00ull), Bitboard(0x0020202020205E00ull),
    Bitboard(0x0040404040403E00ull), Bitboard(0x0080808080807E00ull),
    Bitboard(0x00010101017E0100ull), Bitboard(0x00020202027C0200ull),
    Bitboard(0x00040404047A0400ull), Bitboard(0x0008080808760800ull),
    Bitboard(0x00101010106E1000ull), Bitboard(0x00202020205E2000ull),
    Bitboard(0x00404040403E4000ull), Bitboard(0x00808080807E8000ull),
    Bitboard(0x000101017E010100ull), Bitboard(0x000202027C020200ull),
    Bitboard(0x000404047A040400ull), Bitboard(0x0008080876080800ull),
    Bitboard(0x001010106E101000ull), Bitboard(0x002020205E202000ull),
    Bitboard(0x004040403E404000ull), Bitboard(0x008080807E808000ull),
    Bitboard(0x0001017E01010100ull), Bitboard(0x0002027C02020200ull),
    Bitboard(0x0004047A04040400ull), Bitboard(0x0008087608080800ull),
    Bitboard(0x0010106E10101000ull), Bitboard(0x0020205E20202000ull),
    Bitboard(0x0040403E40404000ull), Bitboard(0x0080807E80808000ull),
    Bitboard(0x00017E0101010100ull), Bitboard(0x00027C0202020200ull),
    Bitboard(0x00047A0404040400ull), Bitboard(0x0008760808080800ull),
    Bitboard(0x00106E1010101000ull), Bitboard(0x00205E2020202000ull),
    Bitboard(0x00403E4040404000ull), Bitboard(0x00807E8080808000ull),
    Bitboard(0x007E010101010100ull), Bitboard(0x007C020202020200ull),
    Bitboard(0x007A040404040400ull), Bitboard(0x0076080808080800ull),
    Bitboard(0x006E101010101000ull), Bitboard(0x005E202020202000ull),
    Bitboard(0x003E404040404000ull), Bitboard(0x007E808080808000ull),
    Bitboard(0x7E01010101010100ull), Bitboard(0x7C02020202020200ull),
    Bitboard(0x7A04040404040400ull), Bitboard(0x7608080808080800ull),
    Bitboard(0x6E10101010101000ull), Bitboard(0x5E20202020202000ull),
    Bitboard(0x3E40404040404000ull), Bitboard(0x7E80808080808000ull)
};

const int Position::magic_bb_b_shift[64] = {
    58, 59, 59, 59, 59, 59, 59, 58,
    59, 59, 59, 59, 59, 59, 59, 59,
    59, 59, 57, 57, 57, 57, 59, 59,
    59, 59, 57, 55, 55, 57, 59, 59,
    59, 59, 57, 55, 55, 57, 59, 59,
    59, 59, 57, 57, 57, 57, 59, 59,
    59, 59, 59, 59, 59, 59, 59, 59,
    58, 59, 59, 59, 59, 59, 59, 58
};

const Bitboard Position::magic_bb_b_magics[64] = {
    Bitboard(0x0002020202020200ull), Bitboard(0x0002020202020000ull),
    Bitboard(0x0004010202000000ull), Bitboard(0x0004040080000000ull),
    Bitboard(0x0001104000000000ull), Bitboard(0x0000821040000000ull),
    Bitboard(0x0000410410400000ull), Bitboard(0x0000104104104000ull),
    Bitboard(0x0000040404040400ull), Bitboard(0x0000020202020200ull),
    Bitboard(0x0000040102020000ull), Bitboard(0x0000040400800000ull),
    Bitboard(0x0000011040000000ull), Bitboard(0x0000008210400000ull),
    Bitboard(0x0000004104104000ull), Bitboard(0x0000002082082000ull),
    Bitboard(0x0004000808080800ull), Bitboard(0x0002000404040400ull),
    Bitboard(0x0001000202020200ull), Bitboard(0x0000800802004000ull),
    Bitboard(0x0000800400A00000ull), Bitboard(0x0000200100884000ull),
    Bitboard(0x0000400082082000ull), Bitboard(0x0000200041041000ull),
    Bitboard(0x0002080010101000ull), Bitboard(0x0001040008080800ull),
    Bitboard(0x0000208004010400ull), Bitboard(0x0000404004010200ull),
    Bitboard(0x0000840000802000ull), Bitboard(0x0000404002011000ull),
    Bitboard(0x0000808001041000ull), Bitboard(0x0000404000820800ull),
    Bitboard(0x0001041000202000ull), Bitboard(0x0000820800101000ull),
    Bitboard(0x0000104400080800ull), Bitboard(0x0000020080080080ull),
    Bitboard(0x0000404040040100ull), Bitboard(0x0000808100020100ull),
    Bitboard(0x0001010100020800ull), Bitboard(0x0000808080010400ull),
    Bitboard(0x0000820820004000ull), Bitboard(0x0000410410002000ull),
    Bitboard(0x0000082088001000ull), Bitboard(0x0000002011000800ull),
    Bitboard(0x0000080100400400ull), Bitboard(0x0001010101000200ull),
    Bitboard(0x0002020202000400ull), Bitboard(0x0001010101000200ull),
    Bitboard(0x0000410410400000ull), Bitboard(0x0000208208200000ull),
    Bitboard(0x0000002084100000ull), Bitboard(0x0000000020880000ull),
    Bitboard(0x0000001002020000ull), Bitboard(0x0000040408020000ull),
    Bitboard(0x0004040404040000ull), Bitboard(0x0002020202020000ull),
    Bitboard(0x0000104104104000ull), Bitboard(0x0000002082082000ull),
    Bitboard(0x0000000020841000ull), Bitboard(0x0000000000208800ull),
    Bitboard(0x0000000010020200ull), Bitboard(0x0000000404080200ull),
    Bitboard(0x0000040404040400ull), Bitboard(0x0002020202020200ull)
};

const Bitboard Position::magic_bb_b_mask[64] = {
    Bitboard(0x0040201008040200ull), Bitboard(0x0000402010080400ull),
    Bitboard(0x0000004020100A00ull), Bitboard(0x0000000040221400ull),
    Bitboard(0x0000000002442800ull), Bitboard(0x0000000204085000ull),
    Bitboard(0x0000020408102000ull), Bitboard(0x0002040810204000ull),
    Bitboard(0x0020100804020000ull), Bitboard(0x0040201008040000ull),
    Bitboard(0x00004020100A0000ull), Bitboard(0x0000004022140000ull),
    Bitboard(0x0000000244280000ull), Bitboard(0x0000020408500000ull),
    Bitboard(0x0002040810200000ull), Bitboard(0x0004081020400000ull),
    Bitboard(0x0010080402000200ull), Bitboard(0x0020100804000400ull),
    Bitboard(0x004020100A000A00ull), Bitboard(0x0000402214001400ull),
    Bitboard(0x0000024428002800ull), Bitboard(0x0002040850005000ull),
    Bitboard(0x0004081020002000ull), Bitboard(0x0008102040004000ull),
    Bitboard(0x0008040200020400ull), Bitboard(0x0010080400040800ull),
    Bitboard(0x0020100A000A1000ull), Bitboard(0x0040221400142200ull),
    Bitboard(0x0002442800284400ull), Bitboard(0x0004085000500800ull),
    Bitboard(0x0008102000201000ull), Bitboard(0x0010204000402000ull),
    Bitboard(0x0004020002040800ull), Bitboard(0x0008040004081000ull),
    Bitboard(0x00100A000A102000ull), Bitboard(0x0022140014224000ull),
    Bitboard(0x0044280028440200ull), Bitboard(0x0008500050080400ull),
    Bitboard(0x0010200020100800ull), Bitboard(0x0020400040201000ull),
    Bitboard(0x0002000204081000ull), Bitboard(0x0004000408102000ull),
    Bitboard(0x000A000A10204000ull), Bitboard(0x0014001422400000ull),
    Bitboard(0x0028002844020000ull), Bitboard(0x0050005008040200ull),
    Bitboard(0x0020002010080400ull), Bitboard(0x0040004020100800ull),
    Bitboard(0x0000020408102000ull), Bitboard(0x0000040810204000ull),
    Bitboard(0x00000A1020400000ull), Bitboard(0x0000142240000000ull),
    Bitboard(0x0000284402000000ull), Bitboard(0x0000500804020000ull),
    Bitboard(0x0000201008040200ull), Bitboard(0x0000402010080400ull),
    Bitboard(0x0002040810204000ull), Bitboard(0x0004081020400000ull),
    Bitboard(0x000A102040000000ull), Bitboard(0x0014224000000000ull),
    Bitboard(0x0028440200000000ull), Bitboard(0x0050080402000000ull),
    Bitboard(0x0020100804020000ull), Bitboard(0x0040201008040200ull)
};

const Bitboard* Position::magic_bb_b_indices[64] = {
    magic_bb_b_db+4992, magic_bb_b_db+2624, magic_bb_b_db+256,  magic_bb_b_db+896,
    magic_bb_b_db+1280, magic_bb_b_db+1664, magic_bb_b_db+4800, magic_bb_b_db+5120,
    magic_bb_b_db+2560, magic_bb_b_db+2656, magic_bb_b_db+288,  magic_bb_b_db+928,
    magic_bb_b_db+1312, magic_bb_b_db+1696, magic_bb_b_db+4832, magic_bb_b_db+4928,
    magic_bb_b_db+0,    magic_bb_b_db+128,  magic_bb_b_db+320,  magic_bb_b_db+960,
    magic_bb_b_db+1344, magic_bb_b_db+1728, magic_bb_b_db+2304, magic_bb_b_db+2432,
    magic_bb_b_db+32,   magic_bb_b_db+160,  magic_bb_b_db+448,  magic_bb_b_db+2752,
    magic_bb_b_db+3776, magic_bb_b_db+1856, magic_bb_b_db+2336, magic_bb_b_db+2464,
    magic_bb_b_db+64,   magic_bb_b_db+192,  magic_bb_b_db+576,  magic_bb_b_db+3264,
    magic_bb_b_db+4288, magic_bb_b_db+1984, magic_bb_b_db+2368, magic_bb_b_db+2496,
    magic_bb_b_db+96,   magic_bb_b_db+224,  magic_bb_b_db+704,  magic_bb_b_db+1088,
    magic_bb_b_db+1472, magic_bb_b_db+2112, magic_bb_b_db+2400, magic_bb_b_db+2528,
    magic_bb_b_db+2592, magic_bb_b_db+2688, magic_bb_b_db+832,  magic_bb_b_db+1216,
    magic_bb_b_db+1600, magic_bb_b_db+2240, magic_bb_b_db+4864, magic_bb_b_db+4960,
    magic_bb_b_db+5056, magic_bb_b_db+2720, magic_bb_b_db+864,  magic_bb_b_db+1248,
    magic_bb_b_db+1632, magic_bb_b_db+2272, magic_bb_b_db+4896, magic_bb_b_db+5184
};

const Bitboard* Position::magic_bb_r_indices[64] = {
    magic_bb_r_db+86016, magic_bb_r_db+73728, magic_bb_r_db+36864, magic_bb_r_db+43008,
    magic_bb_r_db+47104, magic_bb_r_db+51200, magic_bb_r_db+77824, magic_bb_r_db+94208,
    magic_bb_r_db+69632, magic_bb_r_db+32768, magic_bb_r_db+38912, magic_bb_r_db+10240,
    magic_bb_r_db+14336, magic_bb_r_db+53248, magic_bb_r_db+57344, magic_bb_r_db+81920,
    magic_bb_r_db+24576, magic_bb_r_db+33792, magic_bb_r_db+6144,  magic_bb_r_db+11264,
    magic_bb_r_db+15360, magic_bb_r_db+18432, magic_bb_r_db+58368, magic_bb_r_db+61440,
    magic_bb_r_db+26624, magic_bb_r_db+4096,  magic_bb_r_db+7168,  magic_bb_r_db+0,
    magic_bb_r_db+2048,  magic_bb_r_db+19456, magic_bb_r_db+22528, magic_bb_r_db+63488,
    magic_bb_r_db+28672, magic_bb_r_db+5120,  magic_bb_r_db+8192,  magic_bb_r_db+1024,
    magic_bb_r_db+3072,  magic_bb_r_db+20480, magic_bb_r_db+23552, magic_bb_r_db+65536,
    magic_bb_r_db+30720, magic_bb_r_db+34816, magic_bb_r_db+9216,  magic_bb_r_db+12288,
    magic_bb_r_db+16384, magic_bb_r_db+21504, magic_bb_r_db+59392, magic_bb_r_db+67584,
    magic_bb_r_db+71680, magic_bb_r_db+35840, magic_bb_r_db+39936, magic_bb_r_db+13312,
    magic_bb_r_db+17408, magic_bb_r_db+54272, magic_bb_r_db+60416, magic_bb_r_db+83968,
    magic_bb_r_db+90112, magic_bb_r_db+75776, magic_bb_r_db+40960, magic_bb_r_db+45056,
    magic_bb_r_db+49152, magic_bb_r_db+55296, magic_bb_r_db+79872, magic_bb_r_db+98304
};

const uint64_t Position::book_key[781] = {
 UINT64(0x9D39247E33776D41), UINT64(0x2AF7398005AAA5C7), UINT64(0x44DB015024623547), UINT64(0x9C15F73E62A76AE2),
   UINT64(0x75834465489C0C89), UINT64(0x3290AC3A203001BF), UINT64(0x0FBBAD1F61042279), UINT64(0xE83A908FF2FB60CA),
   UINT64(0x0D7E765D58755C10), UINT64(0x1A083822CEAFE02D), UINT64(0x9605D5F0E25EC3B0), UINT64(0xD021FF5CD13A2ED5),
   UINT64(0x40BDF15D4A672E32), UINT64(0x011355146FD56395), UINT64(0x5DB4832046F3D9E5), UINT64(0x239F8B2D7FF719CC),
   UINT64(0x05D1A1AE85B49AA1), UINT64(0x679F848F6E8FC971), UINT64(0x7449BBFF801FED0B), UINT64(0x7D11CDB1C3B7ADF0),
   UINT64(0x82C7709E781EB7CC), UINT64(0xF3218F1C9510786C), UINT64(0x331478F3AF51BBE6), UINT64(0x4BB38DE5E7219443),
   UINT64(0xAA649C6EBCFD50FC), UINT64(0x8DBD98A352AFD40B), UINT64(0x87D2074B81D79217), UINT64(0x19F3C751D3E92AE1),
   UINT64(0xB4AB30F062B19ABF), UINT64(0x7B0500AC42047AC4), UINT64(0xC9452CA81A09D85D), UINT64(0x24AA6C514DA27500),
   UINT64(0x4C9F34427501B447), UINT64(0x14A68FD73C910841), UINT64(0xA71B9B83461CBD93), UINT64(0x03488B95B0F1850F),
   UINT64(0x637B2B34FF93C040), UINT64(0x09D1BC9A3DD90A94), UINT64(0x3575668334A1DD3B), UINT64(0x735E2B97A4C45A23),
   UINT64(0x18727070F1BD400B), UINT64(0x1FCBACD259BF02E7), UINT64(0xD310A7C2CE9B6555), UINT64(0xBF983FE0FE5D8244),
   UINT64(0x9F74D14F7454A824), UINT64(0x51EBDC4AB9BA3035), UINT64(0x5C82C505DB9AB0FA), UINT64(0xFCF7FE8A3430B241),
   UINT64(0x3253A729B9BA3DDE), UINT64(0x8C74C368081B3075), UINT64(0xB9BC6C87167C33E7), UINT64(0x7EF48F2B83024E20),
   UINT64(0x11D505D4C351BD7F), UINT64(0x6568FCA92C76A243), UINT64(0x4DE0B0F40F32A7B8), UINT64(0x96D693460CC37E5D),
   UINT64(0x42E240CB63689F2F), UINT64(0x6D2BDCDAE2919661), UINT64(0x42880B0236E4D951), UINT64(0x5F0F4A5898171BB6),
   UINT64(0x39F890F579F92F88), UINT64(0x93C5B5F47356388B), UINT64(0x63DC359D8D231B78), UINT64(0xEC16CA8AEA98AD76),
   UINT64(0x5355F900C2A82DC7), UINT64(0x07FB9F855A997142), UINT64(0x5093417AA8A7ED5E), UINT64(0x7BCBC38DA25A7F3C),
   UINT64(0x19FC8A768CF4B6D4), UINT64(0x637A7780DECFC0D9), UINT64(0x8249A47AEE0E41F7), UINT64(0x79AD695501E7D1E8),
   UINT64(0x14ACBAF4777D5776), UINT64(0xF145B6BECCDEA195), UINT64(0xDABF2AC8201752FC), UINT64(0x24C3C94DF9C8D3F6),
   UINT64(0xBB6E2924F03912EA), UINT64(0x0CE26C0B95C980D9), UINT64(0xA49CD132BFBF7CC4), UINT64(0xE99D662AF4243939),
   UINT64(0x27E6AD7891165C3F), UINT64(0x8535F040B9744FF1), UINT64(0x54B3F4FA5F40D873), UINT64(0x72B12C32127FED2B),
   UINT64(0xEE954D3C7B411F47), UINT64(0x9A85AC909A24EAA1), UINT64(0x70AC4CD9F04F21F5), UINT64(0xF9B89D3E99A075C2),
   UINT64(0x87B3E2B2B5C907B1), UINT64(0xA366E5B8C54F48B8), UINT64(0xAE4A9346CC3F7CF2), UINT64(0x1920C04D47267BBD),
   UINT64(0x87BF02C6B49E2AE9), UINT64(0x092237AC237F3859), UINT64(0xFF07F64EF8ED14D0), UINT64(0x8DE8DCA9F03CC54E),
   UINT64(0x9C1633264DB49C89), UINT64(0xB3F22C3D0B0B38ED), UINT64(0x390E5FB44D01144B), UINT64(0x5BFEA5B4712768E9),
   UINT64(0x1E1032911FA78984), UINT64(0x9A74ACB964E78CB3), UINT64(0x4F80F7A035DAFB04), UINT64(0x6304D09A0B3738C4),
   UINT64(0x2171E64683023A08), UINT64(0x5B9B63EB9CEFF80C), UINT64(0x506AACF489889342), UINT64(0x1881AFC9A3A701D6),
   UINT64(0x6503080440750644), UINT64(0xDFD395339CDBF4A7), UINT64(0xEF927DBCF00C20F2), UINT64(0x7B32F7D1E03680EC),
   UINT64(0xB9FD7620E7316243), UINT64(0x05A7E8A57DB91B77), UINT64(0xB5889C6E15630A75), UINT64(0x4A750A09CE9573F7),
   UINT64(0xCF464CEC899A2F8A), UINT64(0xF538639CE705B824), UINT64(0x3C79A0FF5580EF7F), UINT64(0xEDE6C87F8477609D),
   UINT64(0x799E81F05BC93F31), UINT64(0x86536B8CF3428A8C), UINT64(0x97D7374C60087B73), UINT64(0xA246637CFF328532),
   UINT64(0x043FCAE60CC0EBA0), UINT64(0x920E449535DD359E), UINT64(0x70EB093B15B290CC), UINT64(0x73A1921916591CBD),
   UINT64(0x56436C9FE1A1AA8D), UINT64(0xEFAC4B70633B8F81), UINT64(0xBB215798D45DF7AF), UINT64(0x45F20042F24F1768),
   UINT64(0x930F80F4E8EB7462), UINT64(0xFF6712FFCFD75EA1), UINT64(0xAE623FD67468AA70), UINT64(0xDD2C5BC84BC8D8FC),
   UINT64(0x7EED120D54CF2DD9), UINT64(0x22FE545401165F1C), UINT64(0xC91800E98FB99929), UINT64(0x808BD68E6AC10365),
   UINT64(0xDEC468145B7605F6), UINT64(0x1BEDE3A3AEF53302), UINT64(0x43539603D6C55602), UINT64(0xAA969B5C691CCB7A),
   UINT64(0xA87832D392EFEE56), UINT64(0x65942C7B3C7E11AE), UINT64(0xDED2D633CAD004F6), UINT64(0x21F08570F420E565),
   UINT64(0xB415938D7DA94E3C), UINT64(0x91B859E59ECB6350), UINT64(0x10CFF333E0ED804A), UINT64(0x28AED140BE0BB7DD),
   UINT64(0xC5CC1D89724FA456), UINT64(0x5648F680F11A2741), UINT64(0x2D255069F0B7DAB3), UINT64(0x9BC5A38EF729ABD4),
   UINT64(0xEF2F054308F6A2BC), UINT64(0xAF2042F5CC5C2858), UINT64(0x480412BAB7F5BE2A), UINT64(0xAEF3AF4A563DFE43),
   UINT64(0x19AFE59AE451497F), UINT64(0x52593803DFF1E840), UINT64(0xF4F076E65F2CE6F0), UINT64(0x11379625747D5AF3),
   UINT64(0xBCE5D2248682C115), UINT64(0x9DA4243DE836994F), UINT64(0x066F70B33FE09017), UINT64(0x4DC4DE189B671A1C),
   UINT64(0x51039AB7712457C3), UINT64(0xC07A3F80C31FB4B4), UINT64(0xB46EE9C5E64A6E7C), UINT64(0xB3819A42ABE61C87),
   UINT64(0x21A007933A522A20), UINT64(0x2DF16F761598AA4F), UINT64(0x763C4A1371B368FD), UINT64(0xF793C46702E086A0),
   UINT64(0xD7288E012AEB8D31), UINT64(0xDE336A2A4BC1C44B), UINT64(0x0BF692B38D079F23), UINT64(0x2C604A7A177326B3),
   UINT64(0x4850E73E03EB6064), UINT64(0xCFC447F1E53C8E1B), UINT64(0xB05CA3F564268D99), UINT64(0x9AE182C8BC9474E8),
   UINT64(0xA4FC4BD4FC5558CA), UINT64(0xE755178D58FC4E76), UINT64(0x69B97DB1A4C03DFE), UINT64(0xF9B5B7C4ACC67C96),
   UINT64(0xFC6A82D64B8655FB), UINT64(0x9C684CB6C4D24417), UINT64(0x8EC97D2917456ED0), UINT64(0x6703DF9D2924E97E),
   UINT64(0xC547F57E42A7444E), UINT64(0x78E37644E7CAD29E), UINT64(0xFE9A44E9362F05FA), UINT64(0x08BD35CC38336615),
   UINT64(0x9315E5EB3A129ACE), UINT64(0x94061B871E04DF75), UINT64(0xDF1D9F9D784BA010), UINT64(0x3BBA57B68871B59D),
   UINT64(0xD2B7ADEEDED1F73F), UINT64(0xF7A255D83BC373F8), UINT64(0xD7F4F2448C0CEB81), UINT64(0xD95BE88CD210FFA7),
   UINT64(0x336F52F8FF4728E7), UINT64(0xA74049DAC312AC71), UINT64(0xA2F61BB6E437FDB5), UINT64(0x4F2A5CB07F6A35B3),
   UINT64(0x87D380BDA5BF7859), UINT64(0x16B9F7E06C453A21), UINT64(0x7BA2484C8A0FD54E), UINT64(0xF3A678CAD9A2E38C),
   UINT64(0x39B0BF7DDE437BA2), UINT64(0xFCAF55C1BF8A4424), UINT64(0x18FCF680573FA594), UINT64(0x4C0563B89F495AC3),
   UINT64(0x40E087931A00930D), UINT64(0x8CFFA9412EB642C1), UINT64(0x68CA39053261169F), UINT64(0x7A1EE967D27579E2),
   UINT64(0x9D1D60E5076F5B6F), UINT64(0x3810E399B6F65BA2), UINT64(0x32095B6D4AB5F9B1), UINT64(0x35CAB62109DD038A),
   UINT64(0xA90B24499FCFAFB1), UINT64(0x77A225A07CC2C6BD), UINT64(0x513E5E634C70E331), UINT64(0x4361C0CA3F692F12),
   UINT64(0xD941ACA44B20A45B), UINT64(0x528F7C8602C5807B), UINT64(0x52AB92BEB9613989), UINT64(0x9D1DFA2EFC557F73),
   UINT64(0x722FF175F572C348), UINT64(0x1D1260A51107FE97), UINT64(0x7A249A57EC0C9BA2), UINT64(0x04208FE9E8F7F2D6),
   UINT64(0x5A110C6058B920A0), UINT64(0x0CD9A497658A5698), UINT64(0x56FD23C8F9715A4C), UINT64(0x284C847B9D887AAE),
   UINT64(0x04FEABFBBDB619CB), UINT64(0x742E1E651C60BA83), UINT64(0x9A9632E65904AD3C), UINT64(0x881B82A13B51B9E2),
   UINT64(0x506E6744CD974924), UINT64(0xB0183DB56FFC6A79), UINT64(0x0ED9B915C66ED37E), UINT64(0x5E11E86D5873D484),
   UINT64(0xF678647E3519AC6E), UINT64(0x1B85D488D0F20CC5), UINT64(0xDAB9FE6525D89021), UINT64(0x0D151D86ADB73615),
   UINT64(0xA865A54EDCC0F019), UINT64(0x93C42566AEF98FFB), UINT64(0x99E7AFEABE000731), UINT64(0x48CBFF086DDF285A),
   UINT64(0x7F9B6AF1EBF78BAF), UINT64(0x58627E1A149BBA21), UINT64(0x2CD16E2ABD791E33), UINT64(0xD363EFF5F0977996),
   UINT64(0x0CE2A38C344A6EED), UINT64(0x1A804AADB9CFA741), UINT64(0x907F30421D78C5DE), UINT64(0x501F65EDB3034D07),
   UINT64(0x37624AE5A48FA6E9), UINT64(0x957BAF61700CFF4E), UINT64(0x3A6C27934E31188A), UINT64(0xD49503536ABCA345),
   UINT64(0x088E049589C432E0), UINT64(0xF943AEE7FEBF21B8), UINT64(0x6C3B8E3E336139D3), UINT64(0x364F6FFA464EE52E),
   UINT64(0xD60F6DCEDC314222), UINT64(0x56963B0DCA418FC0), UINT64(0x16F50EDF91E513AF), UINT64(0xEF1955914B609F93),
   UINT64(0x565601C0364E3228), UINT64(0xECB53939887E8175), UINT64(0xBAC7A9A18531294B), UINT64(0xB344C470397BBA52),
   UINT64(0x65D34954DAF3CEBD), UINT64(0xB4B81B3FA97511E2), UINT64(0xB422061193D6F6A7), UINT64(0x071582401C38434D),
   UINT64(0x7A13F18BBEDC4FF5), UINT64(0xBC4097B116C524D2), UINT64(0x59B97885E2F2EA28), UINT64(0x99170A5DC3115544),
   UINT64(0x6F423357E7C6A9F9), UINT64(0x325928EE6E6F8794), UINT64(0xD0E4366228B03343), UINT64(0x565C31F7DE89EA27),
   UINT64(0x30F5611484119414), UINT64(0xD873DB391292ED4F), UINT64(0x7BD94E1D8E17DEBC), UINT64(0xC7D9F16864A76E94),
   UINT64(0x947AE053EE56E63C), UINT64(0xC8C93882F9475F5F), UINT64(0x3A9BF55BA91F81CA), UINT64(0xD9A11FBB3D9808E4),
   UINT64(0x0FD22063EDC29FCA), UINT64(0xB3F256D8ACA0B0B9), UINT64(0xB03031A8B4516E84), UINT64(0x35DD37D5871448AF),
   UINT64(0xE9F6082B05542E4E), UINT64(0xEBFAFA33D7254B59), UINT64(0x9255ABB50D532280), UINT64(0xB9AB4CE57F2D34F3),
   UINT64(0x693501D628297551), UINT64(0xC62C58F97DD949BF), UINT64(0xCD454F8F19C5126A), UINT64(0xBBE83F4ECC2BDECB),
   UINT64(0xDC842B7E2819E230), UINT64(0xBA89142E007503B8), UINT64(0xA3BC941D0A5061CB), UINT64(0xE9F6760E32CD8021),
   UINT64(0x09C7E552BC76492F), UINT64(0x852F54934DA55CC9), UINT64(0x8107FCCF064FCF56), UINT64(0x098954D51FFF6580),
   UINT64(0x23B70EDB1955C4BF), UINT64(0xC330DE426430F69D), UINT64(0x4715ED43E8A45C0A), UINT64(0xA8D7E4DAB780A08D),
   UINT64(0x0572B974F03CE0BB), UINT64(0xB57D2E985E1419C7), UINT64(0xE8D9ECBE2CF3D73F), UINT64(0x2FE4B17170E59750),
   UINT64(0x11317BA87905E790), UINT64(0x7FBF21EC8A1F45EC), UINT64(0x1725CABFCB045B00), UINT64(0x964E915CD5E2B207),
   UINT64(0x3E2B8BCBF016D66D), UINT64(0xBE7444E39328A0AC), UINT64(0xF85B2B4FBCDE44B7), UINT64(0x49353FEA39BA63B1),
   UINT64(0x1DD01AAFCD53486A), UINT64(0x1FCA8A92FD719F85), UINT64(0xFC7C95D827357AFA), UINT64(0x18A6A990C8B35EBD),
   UINT64(0xCCCB7005C6B9C28D), UINT64(0x3BDBB92C43B17F26), UINT64(0xAA70B5B4F89695A2), UINT64(0xE94C39A54A98307F),
   UINT64(0xB7A0B174CFF6F36E), UINT64(0xD4DBA84729AF48AD), UINT64(0x2E18BC1AD9704A68), UINT64(0x2DE0966DAF2F8B1C),
   UINT64(0xB9C11D5B1E43A07E), UINT64(0x64972D68DEE33360), UINT64(0x94628D38D0C20584), UINT64(0xDBC0D2B6AB90A559),
   UINT64(0xD2733C4335C6A72F), UINT64(0x7E75D99D94A70F4D), UINT64(0x6CED1983376FA72B), UINT64(0x97FCAACBF030BC24),
   UINT64(0x7B77497B32503B12), UINT64(0x8547EDDFB81CCB94), UINT64(0x79999CDFF70902CB), UINT64(0xCFFE1939438E9B24),
   UINT64(0x829626E3892D95D7), UINT64(0x92FAE24291F2B3F1), UINT64(0x63E22C147B9C3403), UINT64(0xC678B6D860284A1C),
   UINT64(0x5873888850659AE7), UINT64(0x0981DCD296A8736D), UINT64(0x9F65789A6509A440), UINT64(0x9FF38FED72E9052F),
   UINT64(0xE479EE5B9930578C), UINT64(0xE7F28ECD2D49EECD), UINT64(0x56C074A581EA17FE), UINT64(0x5544F7D774B14AEF),
   UINT64(0x7B3F0195FC6F290F), UINT64(0x12153635B2C0CF57), UINT64(0x7F5126DBBA5E0CA7), UINT64(0x7A76956C3EAFB413),
   UINT64(0x3D5774A11D31AB39), UINT64(0x8A1B083821F40CB4), UINT64(0x7B4A38E32537DF62), UINT64(0x950113646D1D6E03),
   UINT64(0x4DA8979A0041E8A9), UINT64(0x3BC36E078F7515D7), UINT64(0x5D0A12F27AD310D1), UINT64(0x7F9D1A2E1EBE1327),
   UINT64(0xDA3A361B1C5157B1), UINT64(0xDCDD7D20903D0C25), UINT64(0x36833336D068F707), UINT64(0xCE68341F79893389),
   UINT64(0xAB9090168DD05F34), UINT64(0x43954B3252DC25E5), UINT64(0xB438C2B67F98E5E9), UINT64(0x10DCD78E3851A492),
   UINT64(0xDBC27AB5447822BF), UINT64(0x9B3CDB65F82CA382), UINT64(0xB67B7896167B4C84), UINT64(0xBFCED1B0048EAC50),
   UINT64(0xA9119B60369FFEBD), UINT64(0x1FFF7AC80904BF45), UINT64(0xAC12FB171817EEE7), UINT64(0xAF08DA9177DDA93D),
   UINT64(0x1B0CAB936E65C744), UINT64(0xB559EB1D04E5E932), UINT64(0xC37B45B3F8D6F2BA), UINT64(0xC3A9DC228CAAC9E9),
   UINT64(0xF3B8B6675A6507FF), UINT64(0x9FC477DE4ED681DA), UINT64(0x67378D8ECCEF96CB), UINT64(0x6DD856D94D259236),
   UINT64(0xA319CE15B0B4DB31), UINT64(0x073973751F12DD5E), UINT64(0x8A8E849EB32781A5), UINT64(0xE1925C71285279F5),
   UINT64(0x74C04BF1790C0EFE), UINT64(0x4DDA48153C94938A), UINT64(0x9D266D6A1CC0542C), UINT64(0x7440FB816508C4FE),
   UINT64(0x13328503DF48229F), UINT64(0xD6BF7BAEE43CAC40), UINT64(0x4838D65F6EF6748F), UINT64(0x1E152328F3318DEA),
   UINT64(0x8F8419A348F296BF), UINT64(0x72C8834A5957B511), UINT64(0xD7A023A73260B45C), UINT64(0x94EBC8ABCFB56DAE),
   UINT64(0x9FC10D0F989993E0), UINT64(0xDE68A2355B93CAE6), UINT64(0xA44CFE79AE538BBE), UINT64(0x9D1D84FCCE371425),
   UINT64(0x51D2B1AB2DDFB636), UINT64(0x2FD7E4B9E72CD38C), UINT64(0x65CA5B96B7552210), UINT64(0xDD69A0D8AB3B546D),
   UINT64(0x604D51B25FBF70E2), UINT64(0x73AA8A564FB7AC9E), UINT64(0x1A8C1E992B941148), UINT64(0xAAC40A2703D9BEA0),
   UINT64(0x764DBEAE7FA4F3A6), UINT64(0x1E99B96E70A9BE8B), UINT64(0x2C5E9DEB57EF4743), UINT64(0x3A938FEE32D29981),
   UINT64(0x26E6DB8FFDF5ADFE), UINT64(0x469356C504EC9F9D), UINT64(0xC8763C5B08D1908C), UINT64(0x3F6C6AF859D80055),
   UINT64(0x7F7CC39420A3A545), UINT64(0x9BFB227EBDF4C5CE), UINT64(0x89039D79D6FC5C5C), UINT64(0x8FE88B57305E2AB6),
   UINT64(0xA09E8C8C35AB96DE), UINT64(0xFA7E393983325753), UINT64(0xD6B6D0ECC617C699), UINT64(0xDFEA21EA9E7557E3),
   UINT64(0xB67C1FA481680AF8), UINT64(0xCA1E3785A9E724E5), UINT64(0x1CFC8BED0D681639), UINT64(0xD18D8549D140CAEA),
   UINT64(0x4ED0FE7E9DC91335), UINT64(0xE4DBF0634473F5D2), UINT64(0x1761F93A44D5AEFE), UINT64(0x53898E4C3910DA55),
   UINT64(0x734DE8181F6EC39A), UINT64(0x2680B122BAA28D97), UINT64(0x298AF231C85BAFAB), UINT64(0x7983EED3740847D5),
   UINT64(0x66C1A2A1A60CD889), UINT64(0x9E17E49642A3E4C1), UINT64(0xEDB454E7BADC0805), UINT64(0x50B704CAB602C329),
   UINT64(0x4CC317FB9CDDD023), UINT64(0x66B4835D9EAFEA22), UINT64(0x219B97E26FFC81BD), UINT64(0x261E4E4C0A333A9D),
   UINT64(0x1FE2CCA76517DB90), UINT64(0xD7504DFA8816EDBB), UINT64(0xB9571FA04DC089C8), UINT64(0x1DDC0325259B27DE),
   UINT64(0xCF3F4688801EB9AA), UINT64(0xF4F5D05C10CAB243), UINT64(0x38B6525C21A42B0E), UINT64(0x36F60E2BA4FA6800),
   UINT64(0xEB3593803173E0CE), UINT64(0x9C4CD6257C5A3603), UINT64(0xAF0C317D32ADAA8A), UINT64(0x258E5A80C7204C4B),
   UINT64(0x8B889D624D44885D), UINT64(0xF4D14597E660F855), UINT64(0xD4347F66EC8941C3), UINT64(0xE699ED85B0DFB40D),
   UINT64(0x2472F6207C2D0484), UINT64(0xC2A1E7B5B459AEB5), UINT64(0xAB4F6451CC1D45EC), UINT64(0x63767572AE3D6174),
   UINT64(0xA59E0BD101731A28), UINT64(0x116D0016CB948F09), UINT64(0x2CF9C8CA052F6E9F), UINT64(0x0B090A7560A968E3),
   UINT64(0xABEEDDB2DDE06FF1), UINT64(0x58EFC10B06A2068D), UINT64(0xC6E57A78FBD986E0), UINT64(0x2EAB8CA63CE802D7),
   UINT64(0x14A195640116F336), UINT64(0x7C0828DD624EC390), UINT64(0xD74BBE77E6116AC7), UINT64(0x804456AF10F5FB53),
   UINT64(0xEBE9EA2ADF4321C7), UINT64(0x03219A39EE587A30), UINT64(0x49787FEF17AF9924), UINT64(0xA1E9300CD8520548),
   UINT64(0x5B45E522E4B1B4EF), UINT64(0xB49C3B3995091A36), UINT64(0xD4490AD526F14431), UINT64(0x12A8F216AF9418C2),
   UINT64(0x001F837CC7350524), UINT64(0x1877B51E57A764D5), UINT64(0xA2853B80F17F58EE), UINT64(0x993E1DE72D36D310),
   UINT64(0xB3598080CE64A656), UINT64(0x252F59CF0D9F04BB), UINT64(0xD23C8E176D113600), UINT64(0x1BDA0492E7E4586E),
   UINT64(0x21E0BD5026C619BF), UINT64(0x3B097ADAF088F94E), UINT64(0x8D14DEDB30BE846E), UINT64(0xF95CFFA23AF5F6F4),
   UINT64(0x3871700761B3F743), UINT64(0xCA672B91E9E4FA16), UINT64(0x64C8E531BFF53B55), UINT64(0x241260ED4AD1E87D),
   UINT64(0x106C09B972D2E822), UINT64(0x7FBA195410E5CA30), UINT64(0x7884D9BC6CB569D8), UINT64(0x0647DFEDCD894A29),
   UINT64(0x63573FF03E224774), UINT64(0x4FC8E9560F91B123), UINT64(0x1DB956E450275779), UINT64(0xB8D91274B9E9D4FB),
   UINT64(0xA2EBEE47E2FBFCE1), UINT64(0xD9F1F30CCD97FB09), UINT64(0xEFED53D75FD64E6B), UINT64(0x2E6D02C36017F67F),
   UINT64(0xA9AA4D20DB084E9B), UINT64(0xB64BE8D8B25396C1), UINT64(0x70CB6AF7C2D5BCF0), UINT64(0x98F076A4F7A2322E),
   UINT64(0xBF84470805E69B5F), UINT64(0x94C3251F06F90CF3), UINT64(0x3E003E616A6591E9), UINT64(0xB925A6CD0421AFF3),
   UINT64(0x61BDD1307C66E300), UINT64(0xBF8D5108E27E0D48), UINT64(0x240AB57A8B888B20), UINT64(0xFC87614BAF287E07),
   UINT64(0xEF02CDD06FFDB432), UINT64(0xA1082C0466DF6C0A), UINT64(0x8215E577001332C8), UINT64(0xD39BB9C3A48DB6CF),
   UINT64(0x2738259634305C14), UINT64(0x61CF4F94C97DF93D), UINT64(0x1B6BACA2AE4E125B), UINT64(0x758F450C88572E0B),
   UINT64(0x959F587D507A8359), UINT64(0xB063E962E045F54D), UINT64(0x60E8ED72C0DFF5D1), UINT64(0x7B64978555326F9F),
   UINT64(0xFD080D236DA814BA), UINT64(0x8C90FD9B083F4558), UINT64(0x106F72FE81E2C590), UINT64(0x7976033A39F7D952),
   UINT64(0xA4EC0132764CA04B), UINT64(0x733EA705FAE4FA77), UINT64(0xB4D8F77BC3E56167), UINT64(0x9E21F4F903B33FD9),
   UINT64(0x9D765E419FB69F6D), UINT64(0xD30C088BA61EA5EF), UINT64(0x5D94337FBFAF7F5B), UINT64(0x1A4E4822EB4D7A59),
   UINT64(0x6FFE73E81B637FB3), UINT64(0xDDF957BC36D8B9CA), UINT64(0x64D0E29EEA8838B3), UINT64(0x08DD9BDFD96B9F63),
   UINT64(0x087E79E5A57D1D13), UINT64(0xE328E230E3E2B3FB), UINT64(0x1C2559E30F0946BE), UINT64(0x720BF5F26F4D2EAA),
   UINT64(0xB0774D261CC609DB), UINT64(0x443F64EC5A371195), UINT64(0x4112CF68649A260E), UINT64(0xD813F2FAB7F5C5CA),
   UINT64(0x660D3257380841EE), UINT64(0x59AC2C7873F910A3), UINT64(0xE846963877671A17), UINT64(0x93B633ABFA3469F8),
   UINT64(0xC0C0F5A60EF4CDCF), UINT64(0xCAF21ECD4377B28C), UINT64(0x57277707199B8175), UINT64(0x506C11B9D90E8B1D),
   UINT64(0xD83CC2687A19255F), UINT64(0x4A29C6465A314CD1), UINT64(0xED2DF21216235097), UINT64(0xB5635C95FF7296E2),
   UINT64(0x22AF003AB672E811), UINT64(0x52E762596BF68235), UINT64(0x9AEBA33AC6ECC6B0), UINT64(0x944F6DE09134DFB6),
   UINT64(0x6C47BEC883A7DE39), UINT64(0x6AD047C430A12104), UINT64(0xA5B1CFDBA0AB4067), UINT64(0x7C45D833AFF07862),
   UINT64(0x5092EF950A16DA0B), UINT64(0x9338E69C052B8E7B), UINT64(0x455A4B4CFE30E3F5), UINT64(0x6B02E63195AD0CF8),
   UINT64(0x6B17B224BAD6BF27), UINT64(0xD1E0CCD25BB9C169), UINT64(0xDE0C89A556B9AE70), UINT64(0x50065E535A213CF6),
   UINT64(0x9C1169FA2777B874), UINT64(0x78EDEFD694AF1EED), UINT64(0x6DC93D9526A50E68), UINT64(0xEE97F453F06791ED),
   UINT64(0x32AB0EDB696703D3), UINT64(0x3A6853C7E70757A7), UINT64(0x31865CED6120F37D), UINT64(0x67FEF95D92607890),
   UINT64(0x1F2B1D1F15F6DC9C), UINT64(0xB69E38A8965C6B65), UINT64(0xAA9119FF184CCCF4), UINT64(0xF43C732873F24C13),
   UINT64(0xFB4A3D794A9A80D2), UINT64(0x3550C2321FD6109C), UINT64(0x371F77E76BB8417E), UINT64(0x6BFA9AAE5EC05779),
   UINT64(0xCD04F3FF001A4778), UINT64(0xE3273522064480CA), UINT64(0x9F91508BFFCFC14A), UINT64(0x049A7F41061A9E60),
   UINT64(0xFCB6BE43A9F2FE9B), UINT64(0x08DE8A1C7797DA9B), UINT64(0x8F9887E6078735A1), UINT64(0xB5B4071DBFC73A66),
   UINT64(0x230E343DFBA08D33), UINT64(0x43ED7F5A0FAE657D), UINT64(0x3A88A0FBBCB05C63), UINT64(0x21874B8B4D2DBC4F),
   UINT64(0x1BDEA12E35F6A8C9), UINT64(0x53C065C6C8E63528), UINT64(0xE34A1D250E7A8D6B), UINT64(0xD6B04D3B7651DD7E),
   UINT64(0x5E90277E7CB39E2D), UINT64(0x2C046F22062DC67D), UINT64(0xB10BB459132D0A26), UINT64(0x3FA9DDFB67E2F199),
   UINT64(0x0E09B88E1914F7AF), UINT64(0x10E8B35AF3EEAB37), UINT64(0x9EEDECA8E272B933), UINT64(0xD4C718BC4AE8AE5F),
   UINT64(0x81536D601170FC20), UINT64(0x91B534F885818A06), UINT64(0xEC8177F83F900978), UINT64(0x190E714FADA5156E),
   UINT64(0xB592BF39B0364963), UINT64(0x89C350C893AE7DC1), UINT64(0xAC042E70F8B383F2), UINT64(0xB49B52E587A1EE60),
   UINT64(0xFB152FE3FF26DA89), UINT64(0x3E666E6F69AE2C15), UINT64(0x3B544EBE544C19F9), UINT64(0xE805A1E290CF2456),
   UINT64(0x24B33C9D7ED25117), UINT64(0xE74733427B72F0C1), UINT64(0x0A804D18B7097475), UINT64(0x57E3306D881EDB4F),
   UINT64(0x4AE7D6A36EB5DBCB), UINT64(0x2D8D5432157064C8), UINT64(0xD1E649DE1E7F268B), UINT64(0x8A328A1CEDFE552C),
   UINT64(0x07A3AEC79624C7DA), UINT64(0x84547DDC3E203C94), UINT64(0x990A98FD5071D263), UINT64(0x1A4FF12616EEFC89),
   UINT64(0xF6F7FD1431714200), UINT64(0x30C05B1BA332F41C), UINT64(0x8D2636B81555A786), UINT64(0x46C9FEB55D120902),
   UINT64(0xCCEC0A73B49C9921), UINT64(0x4E9D2827355FC492), UINT64(0x19EBB029435DCB0F), UINT64(0x4659D2B743848A2C),
   UINT64(0x963EF2C96B33BE31), UINT64(0x74F85198B05A2E7D), UINT64(0x5A0F544DD2B1FB18), UINT64(0x03727073C2E134B1),
   UINT64(0xC7F6AA2DE59AEA61), UINT64(0x352787BAA0D7C22F), UINT64(0x9853EAB63B5E0B35), UINT64(0xABBDCDD7ED5C0860),
   UINT64(0xCF05DAF5AC8D77B0), UINT64(0x49CAD48CEBF4A71E), UINT64(0x7A4C10EC2158C4A6), UINT64(0xD9E92AA246BF719E),
   UINT64(0x13AE978D09FE5557), UINT64(0x730499AF921549FF), UINT64(0x4E4B705B92903BA4), UINT64(0xFF577222C14F0A3A),
   UINT64(0x55B6344CF97AAFAE), UINT64(0xB862225B055B6960), UINT64(0xCAC09AFBDDD2CDB4), UINT64(0xDAF8E9829FE96B5F),
   UINT64(0xB5FDFC5D3132C498), UINT64(0x310CB380DB6F7503), UINT64(0xE87FBB46217A360E), UINT64(0x2102AE466EBB1148),
   UINT64(0xF8549E1A3AA5E00D), UINT64(0x07A69AFDCC42261A), UINT64(0xC4C118BFE78FEAAE), UINT64(0xF9F4892ED96BD438),
   UINT64(0x1AF3DBE25D8F45DA), UINT64(0xF5B4B0B0D2DEEEB4), UINT64(0x962ACEEFA82E1C84), UINT64(0x046E3ECAAF453CE9),
   UINT64(0xF05D129681949A4C), UINT64(0x964781CE734B3C84), UINT64(0x9C2ED44081CE5FBD), UINT64(0x522E23F3925E319E),
   UINT64(0x177E00F9FC32F791), UINT64(0x2BC60A63A6F3B3F2), UINT64(0x222BBFAE61725606), UINT64(0x486289DDCC3D6780),
   UINT64(0x7DC7785B8EFDFC80), UINT64(0x8AF38731C02BA980), UINT64(0x1FAB64EA29A2DDF7), UINT64(0xE4D9429322CD065A),
   UINT64(0x9DA058C67844F20C), UINT64(0x24C0E332B70019B0), UINT64(0x233003B5A6CFE6AD), UINT64(0xD586BD01C5C217F6),
   UINT64(0x5E5637885F29BC2B), UINT64(0x7EBA726D8C94094B), UINT64(0x0A56A5F0BFE39272), UINT64(0xD79476A84EE20D06),
   UINT64(0x9E4C1269BAA4BF37), UINT64(0x17EFEE45B0DEE640), UINT64(0x1D95B0A5FCF90BC6), UINT64(0x93CBE0B699C2585D),
   UINT64(0x65FA4F227A2B6D79), UINT64(0xD5F9E858292504D5), UINT64(0xC2B5A03F71471A6F), UINT64(0x59300222B4561E00),
   UINT64(0xCE2F8642CA0712DC), UINT64(0x7CA9723FBB2E8988), UINT64(0x2785338347F2BA08), UINT64(0xC61BB3A141E50E8C),
   UINT64(0x150F361DAB9DEC26), UINT64(0x9F6A419D382595F4), UINT64(0x64A53DC924FE7AC9), UINT64(0x142DE49FFF7A7C3D),
   UINT64(0x0C335248857FA9E7), UINT64(0x0A9C32D5EAE45305), UINT64(0xE6C42178C4BBB92E), UINT64(0x71F1CE2490D20B07),
   UINT64(0xF1BCC3D275AFE51A), UINT64(0xE728E8C83C334074), UINT64(0x96FBF83A12884624), UINT64(0x81A1549FD6573DA5),
   UINT64(0x5FA7867CAF35E149), UINT64(0x56986E2EF3ED091B), UINT64(0x917F1DD5F8886C61), UINT64(0xD20D8C88C8FFE65F),
   UINT64(0x31D71DCE64B2C310), UINT64(0xF165B587DF898190), UINT64(0xA57E6339DD2CF3A0), UINT64(0x1EF6E6DBB1961EC9),
   UINT64(0x70CC73D90BC26E24), UINT64(0xE21A6B35DF0C3AD7), UINT64(0x003A93D8B2806962), UINT64(0x1C99DED33CB890A1),
   UINT64(0xCF3145DE0ADD4289), UINT64(0xD0E4427A5514FB72), UINT64(0x77C621CC9FB3A483), UINT64(0x67A34DAC4356550B),
   UINT64(0xF8D626AAAF278509)

};

const int Position::PawnFrom[2][4] = {{-16,-8,-9,-7},{16,8,7,9}};

const int Position::Pawn_File[8] = {-3, -1, +0, +1, +1, +0, -1, -3};
const int Position::Pawn_Rank[8] = {+0, +0, +0, +0, +2, +4, +8, +0};
const int Position::Knight_Line[8] = {-4, -2, +0, +1, +1, +0, -2, -4};
const int Position::Knight_Rank[8] = {-2, -1, +0, +1, +2, +3, +2, +1};
const int Position::Bishop_Line[8] = {-3, -1, +0, +1, +1, +0, -1, -3};
const int Position::Rook_File[8] = {-2, -1, +0, +1, +1, +0, -1, -2};
const int Position::Queen_Line[8] = {-3, -1, +0, +1, +1, +0, -1, -3};
const int Position::King_File[8] = {+3, +4, +2, +0, +0, +2, +4, +3};
const int Position::King_Rank[8] = {+1, +0, -2, -3, -4, -5, -6, -7};
const int Position::King_Line[8] = {-3, -1, +0, +1, +1, +0, -1, -3};
const int Position::Pawn_File_Opening = 5;
const int Position::Pawn_Rank_Endgame = 2;
const int Position::Knight_Center[2] = {5, 5};
const int Position::Knight_Rank_Opening = 5;
const int Position::Knight_Back_Rank_Opening = 0;
const int Position::Knight_Trapped = 100;
const int Position::Bishop_Center[2] = {2, 3};
const int Position::Bishop_Back_Rank_Opening = 10;
const int Position::Bishop_Diagonal_Opening = 4;
const int Position::Rook_File_Opening = 3;
const int Position::Queen_Center[2] = {0, 4};
const int Position::Queen_Back_Rank_Opening = 5;
const int Position::King_File_Opening = 10;
const int Position::King_Rank_Opening = 10;
const int Position::King_Center_Endgame = 12;

Position::AttackFunction Position::attack[14];
Position::AttackFunctionBB Position::attack_bb[14];

Key Position::SqKey[14][64];
Key Position::MatKey[14][17];
Key Position::EpKey[64];
Key Position::CastleKey[13];
Key Position::StmKey;

Bitboard Position::PawnAttack[2][64];
Bitboard Position::KnightAttack[64];
Bitboard Position::KingAttack[64];
Bitboard Position::KingAttack2[64];
Bitboard Position::BishopAttack[64];
Bitboard Position::RookAttack[64];
Bitboard Position::QueenAttack[64];

Bitboard Position::magic_bb_r_db[102400];
Bitboard Position::magic_bb_b_db[5248];

int Position::PVT[14][64][2];
int Position::Direction[64][64];

void Position::init(){
    init_keys();
    init_attack();
    init_magic_bb();
    init_pvt();
    init_direction();
}

void Position::init_attack(){
    Bitboard mask;
    for(Square sq=A1; sq<=H8; sq++) {
        mask = BB_1<<sq;
        PawnAttack[White][sq]= shift_up_left(mask) | shift_up_right(mask);
        PawnAttack[Black][sq]= shift_down_left(mask) | shift_down_right(mask);
        BishopAttack[sq] = bishop_attack(sq,0);
        RookAttack[sq] = rook_attack(sq,0);
        QueenAttack[sq] = queen_attack(sq,0);
    }

    for(Square sq=A1; sq<=H8; sq++){
        mask = BB_1<<sq;
        KnightAttack[sq] = shift_left(shift_2_up(mask)) | shift_right(shift_2_up(mask))
                           | shift_left(shift_2_down(mask)) | shift_right(shift_2_down(mask))
                           | shift_2_left(shift_up(mask)) | shift_2_right(shift_up(mask))
                           | shift_2_left(shift_down(mask)) | shift_2_right(shift_down(mask));
    }

    for(Square s=A1; s<=H8; s++) {
        mask = BB_1<<s;
        KingAttack[s] = shift_left(mask) | shift_right(mask)
                         | shift_up(mask) | shift_down(mask)
                         | shift_up_left(mask) | shift_up_right(mask)
                         | shift_down_left(mask) | shift_down_right(mask);
        mask = KingAttack[s];
        KingAttack2[s] = shift_left(mask) | shift_right(mask)
                         | shift_up(mask) | shift_down(mask)
                         | shift_up_left(mask) | shift_up_right(mask)
                         | shift_down_left(mask) | shift_down_right(mask);
    }

    attack[W] = attack[B] = NULL;
    attack[WP] = attack[BP] = NULL;
    attack[WN] = attack[BN] = &Position::knight_attack;
    attack[WB] = attack[BB] = &Position::bishop_attack;
    attack[WR] = attack[BR] = &Position::rook_attack;
    attack[WQ] = attack[BQ] = &Position::queen_attack;
    attack[WK] = attack[BK] = &Position::king_attack;

    attack_bb[W] = attack_bb[B] = NULL;
    attack_bb[WP] = attack_bb[BP] = NULL;
    attack_bb[WN] = attack_bb[BN] = &Position::knight_attack;
    attack_bb[WB] = attack_bb[BB] = &Position::bishop_attack;
    attack_bb[WR] = attack_bb[BR] = &Position::rook_attack;
    attack_bb[WQ] = attack_bb[BQ] = &Position::queen_attack;
    attack_bb[WK] = attack_bb[BK] = NULL;
}

void Position::init_keys(){
	srand(time(NULL));
    for(int i=0; i<14; i++){
        for(int j=0; j<64; j++)
			SqKey[i][j] = myrand64();
        for(int j=0; j<17; j++)
			MatKey[i][j] = myrand64();
    }

    for(int i=0; i<64; i++)
		EpKey[i] = myrand64();

    for(int i=0; i<13; i++)
		CastleKey[i] = myrand64();

	StmKey = myrand64();
}

void Position::init_magic_bb(){
    Square init_magic_bitpos64_db[64] = {
        Square(63), Square(0),  Square(58), Square(1),
        Square(59), Square(47), Square(53), Square(2),
        Square(60), Square(39), Square(48), Square(27),
        Square(54), Square(33), Square(42), Square(3),
        Square(61), Square(51), Square(37), Square(40),
        Square(49), Square(18), Square(28), Square(20),
        Square(55), Square(30), Square(34), Square(11),
        Square(43), Square(14), Square(22), Square(4),
        Square(62), Square(57), Square(46), Square(52),
        Square(38), Square(26), Square(32), Square(41),
        Square(50), Square(36), Square(17), Square(19),
        Square(29), Square(10), Square(13), Square(21),
        Square(56), Square(45), Square(25), Square(31),
        Square(35), Square(16), Square(9),  Square(12),
        Square(44), Square(24), Square(15), Square(8),
        Square(23),  Square(7), Square(6),  Square(5)
     };

     Bitboard* magic_bb_b_indices2[64] = {
        magic_bb_b_db+4992, magic_bb_b_db+2624,  magic_bb_b_db+256,  magic_bb_b_db+896,
        magic_bb_b_db+1280, magic_bb_b_db+1664, magic_bb_b_db+4800, magic_bb_b_db+5120,
        magic_bb_b_db+2560, magic_bb_b_db+2656,  magic_bb_b_db+288,  magic_bb_b_db+928,
        magic_bb_b_db+1312, magic_bb_b_db+1696, magic_bb_b_db+4832, magic_bb_b_db+4928,
        magic_bb_b_db+0,     magic_bb_b_db+128,  magic_bb_b_db+320,  magic_bb_b_db+960,
        magic_bb_b_db+1344, magic_bb_b_db+1728, magic_bb_b_db+2304, magic_bb_b_db+2432,
        magic_bb_b_db+32,    magic_bb_b_db+160,  magic_bb_b_db+448, magic_bb_b_db+2752,
        magic_bb_b_db+3776, magic_bb_b_db+1856, magic_bb_b_db+2336, magic_bb_b_db+2464,
        magic_bb_b_db+64,    magic_bb_b_db+192,  magic_bb_b_db+576, magic_bb_b_db+3264,
        magic_bb_b_db+4288, magic_bb_b_db+1984, magic_bb_b_db+2368, magic_bb_b_db+2496,
        magic_bb_b_db+96,    magic_bb_b_db+224,  magic_bb_b_db+704, magic_bb_b_db+1088,
        magic_bb_b_db+1472, magic_bb_b_db+2112, magic_bb_b_db+2400, magic_bb_b_db+2528,
        magic_bb_b_db+2592, magic_bb_b_db+2688,  magic_bb_b_db+832, magic_bb_b_db+1216,
        magic_bb_b_db+1600, magic_bb_b_db+2240, magic_bb_b_db+4864, magic_bb_b_db+4960,
        magic_bb_b_db+5056, magic_bb_b_db+2720,  magic_bb_b_db+864, magic_bb_b_db+1248,
        magic_bb_b_db+1632, magic_bb_b_db+2272, magic_bb_b_db+4896, magic_bb_b_db+5184
    };

    Bitboard* magic_bb_r_indices2[64] = {
        magic_bb_r_db+86016, magic_bb_r_db+73728, magic_bb_r_db+36864, magic_bb_r_db+43008,
        magic_bb_r_db+47104, magic_bb_r_db+51200, magic_bb_r_db+77824, magic_bb_r_db+94208,
        magic_bb_r_db+69632, magic_bb_r_db+32768, magic_bb_r_db+38912, magic_bb_r_db+10240,
        magic_bb_r_db+14336, magic_bb_r_db+53248, magic_bb_r_db+57344, magic_bb_r_db+81920,
        magic_bb_r_db+24576, magic_bb_r_db+33792,  magic_bb_r_db+6144, magic_bb_r_db+11264,
        magic_bb_r_db+15360, magic_bb_r_db+18432, magic_bb_r_db+58368, magic_bb_r_db+61440,
        magic_bb_r_db+26624,  magic_bb_r_db+4096,  magic_bb_r_db+7168,     magic_bb_r_db+0,
        magic_bb_r_db+2048,  magic_bb_r_db+19456, magic_bb_r_db+22528, magic_bb_r_db+63488,
        magic_bb_r_db+28672,  magic_bb_r_db+5120,  magic_bb_r_db+8192,  magic_bb_r_db+1024,
        magic_bb_r_db+3072,  magic_bb_r_db+20480, magic_bb_r_db+23552, magic_bb_r_db+65536,
        magic_bb_r_db+30720, magic_bb_r_db+34816,  magic_bb_r_db+9216, magic_bb_r_db+12288,
        magic_bb_r_db+16384, magic_bb_r_db+21504, magic_bb_r_db+59392, magic_bb_r_db+67584,
        magic_bb_r_db+71680, magic_bb_r_db+35840, magic_bb_r_db+39936, magic_bb_r_db+13312,
        magic_bb_r_db+17408, magic_bb_r_db+54272, magic_bb_r_db+60416, magic_bb_r_db+83968,
        magic_bb_r_db+90112, magic_bb_r_db+75776, magic_bb_r_db+40960, magic_bb_r_db+45056,
        magic_bb_r_db+49152, magic_bb_r_db+55296, magic_bb_r_db+79872, magic_bb_r_db+98304
    };

    for(Square i=A1;i<=H8;i++){
        Square sq[64];
        int numSq=0;
        Bitboard temp=magic_bb_b_mask[i];
        while(temp){
            Bitboard bit=temp&-temp;
            sq[numSq++]=init_magic_bitpos64_db[(bit*Bitboard(0x07EDD5E59A4E28C2ull))>>58];
            temp^=bit;
        }
        for(temp=0;temp<(((Bitboard)(1))<<numSq);temp++){
            Bitboard tempocc=init_magic_bb_occ(sq,numSq,temp);
            *(magic_bb_b_indices2[i]+(((tempocc)*magic_bb_b_magics[i])>>magic_bb_b_shift[i]))=
                init_magic_bb_b(i,tempocc);
        }
    }

    for(Square i=A1;i<=H8;i++){
        Square sq[64];
        int numSq=0;
        Bitboard temp=magic_bb_r_mask[i];
        while(temp){
            Bitboard bit=temp&-temp;
            sq[numSq++]=init_magic_bitpos64_db[(bit*Bitboard(0x07EDD5E59A4E28C2ull))>>58];
            temp^=bit;
        }
        for(temp=0;temp<(((Bitboard)(1))<<numSq);temp++){
            Bitboard tempocc=init_magic_bb_occ(sq,numSq,temp);
            *(magic_bb_r_indices2[i]+(((tempocc)*magic_bb_r_magics[i])>>magic_bb_r_shift[i]))=
                init_magic_bb_r(i,tempocc);
        }
    }
}

Bitboard Position::init_magic_bb_r(const Square sq, const Bitboard occ){
    Bitboard ret=0;
    Bitboard bit;
    Bitboard rowbits=(((Bitboard)0xFF)<<(8*(sq/8)));

    bit=(((Bitboard)(1))<<sq);
    do{
        bit<<=8;
        ret|=bit;
    }while(bit && !(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    do{
        bit>>=8;
        ret|=bit;
    }while(bit && !(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    do{
        bit<<=1;
        if(bit&rowbits) ret|=bit;
        else break;
    }while(!(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    do{
        bit>>=1;
        if(bit&rowbits) ret|=bit;
        else break;
    }while(!(bit&occ));
    return ret;
}

Bitboard Position::init_magic_bb_b(const Square sq, const Bitboard occ){
    Bitboard ret=0;
    Bitboard bit;
    Bitboard bit2;
    Bitboard rowbits=(((Bitboard)0xFF)<<(8*(sq/8)));

    bit=(((Bitboard)(1))<<sq);
    bit2=bit;
    do{
        bit<<=8-1;
        bit2>>=1;
        if(bit2&rowbits) ret|=bit;
        else break;
    }while(bit && !(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    bit2=bit;
    do{
        bit<<=8+1;
        bit2<<=1;
        if(bit2&rowbits) ret|=bit;
        else break;
    }while(bit && !(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    bit2=bit;
    do{
        bit>>=8-1;
        bit2<<=1;
        if(bit2&rowbits) ret|=bit;
        else break;
    }while(bit && !(bit&occ));
    bit=(((Bitboard)(1))<<sq);
    bit2=bit;
    do{
        bit>>=8+1;
        bit2>>=1;
        if(bit2&rowbits) ret|=bit;
        else break;
    }while(bit && !(bit&occ));
    return ret;
}

Bitboard Position::init_magic_bb_occ(const Square* sq, const int numSq, const Bitboard linocc){
    Bitboard ret=0;
    for(int i=0;i<numSq;i++)
        if(linocc&(((Bitboard)(1))<<i))
            ret|=(((Bitboard)(1))<<sq[i]);
    return ret;
}

void Position::init_pvt(){ 
    Piece p;
    Square sq;
    Phase phase;

    for(p=W; p<=BK; p++){
        for(sq=A1; sq<=H8; sq++){
            for(phase=Opening; phase<=Endgame; phase++){
                PVT[p][sq][phase] = 0;
            }
        }
    }

    /* Pawn */
    for(sq=A1; sq<=H8; sq++){
        PVT[WP][sq][Opening] += Pawn_File[file(sq)] * Pawn_File_Opening;
 //       PVT[WP][sq][Endgame] += Pawn_Rank[rank(sq)] * Pawn_Rank_Endgame;
    }

     /* Center control */
     PVT[WP][D3][Opening] += 10;
     PVT[WP][E3][Opening] += 10;
     PVT[WP][D4][Opening] += 20;
     PVT[WP][E4][Opening] += 20;
     PVT[WP][D5][Opening] += 10;
     PVT[WP][E5][Opening] += 10;

     /* Knight */
     for(sq=A1; sq<=H8; sq++){
        PVT[WN][sq][Opening] += Knight_Line[file(sq)] * Knight_Center[Opening];
        PVT[WN][sq][Opening] += Knight_Line[rank(sq)] * Knight_Center[Opening];
        PVT[WN][sq][Opening] += Knight_Rank[rank(sq)] * Knight_Rank_Opening;
        PVT[WN][sq][Endgame] += Knight_Line[file(sq)] * Knight_Center[Endgame];
        PVT[WN][sq][Endgame] += Knight_Line[rank(sq)] * Knight_Center[Endgame];
    }

     /* Back rank */
     for(sq=A1; sq<=H1; sq++) PVT[WN][sq][Opening] -= Knight_Back_Rank_Opening;

     /* Trapped */
     PVT[WN][A8][Opening] -= Knight_Trapped;
     PVT[WN][H8][Opening] -= Knight_Trapped;

     /* Bishop */
     for(sq=A1; sq<=H8; sq++){
        PVT[WB][sq][Opening] += Bishop_Line[file(sq)] * Bishop_Center[Opening];
        PVT[WB][sq][Opening] += Bishop_Line[rank(sq)] * Bishop_Center[Opening];
        PVT[WB][sq][Endgame] += Bishop_Line[file(sq)] * Bishop_Center[Endgame];
        PVT[WB][sq][Endgame] += Bishop_Line[rank(sq)] * Bishop_Center[Endgame];
    }

     /* Back rank */
     for(sq=A1; sq<=H1; sq++) PVT[WB][sq][Opening] -= Bishop_Back_Rank_Opening;

     /* Main diagonals*/
     for(File f=FILE_A; f<=FILE_H; f++){
        sq = get_square(f,Rank(f));
        PVT[WB][sq][Opening] += Bishop_Diagonal_Opening;
        PVT[WB][opposite(sq)][Opening] += Bishop_Diagonal_Opening;
    }

    /* Rooks */
    for(sq=A1; sq<=H8; sq++) PVT[WR][sq][Opening] += Rook_File[file(sq)] * Rook_File_Opening;

    /* Queens */
    for(sq=A1; sq<=H8; sq++){
        PVT[WQ][sq][Opening] += Queen_Line[file(sq)] * Queen_Center[Opening];
        PVT[WQ][sq][Opening] += Queen_Line[rank(sq)] * Queen_Center[Opening];
        PVT[WQ][sq][Endgame] += Queen_Line[file(sq)] * Queen_Center[Endgame];
        PVT[WQ][sq][Endgame] += Queen_Line[rank(sq)] * Queen_Center[Endgame];
    }

    /* Back rank */
    for(sq=A1; sq<=H1; sq++) PVT[WQ][sq][Opening] -= Queen_Back_Rank_Opening;

    /* Kings */
    for(sq=A1; sq<=H8; sq++){
        PVT[WK][sq][Opening] += King_File[file(sq)] * King_File_Opening;
        PVT[WK][sq][Opening] += King_Rank[rank(sq)] * King_Rank_Opening;
        PVT[WK][sq][Endgame] += King_Line[file(sq)] * King_Center_Endgame;
        PVT[WK][sq][Endgame] += King_Line[rank(sq)] * King_Center_Endgame;
    }

    /* Symmetry copy for black */
    for (p = W; p <= BK; p+=2) {
        for (sq = A1; sq <= H8; sq++) {
            for (phase= Opening; phase <= Endgame; phase++) {
                PVT[p+1][sq][phase] = -PVT[p][opposite(sq)][phase];
            }
        }
    }
}

void Position::init_direction(){
    for(Square from = A1; from<=H8; from++){
        for(Square to = A1; to<=H8; to++) Direction[from][to] = 0;

        for(Square to = from+8; to<64; to+=8) Direction[from][to] = 8;
        for(Square to = from-8; to>-1; to-=8) Direction[from][to] = 8;

        for(Square to = from+1; (to%8) != 0; to++) Direction[from][to] = 1;
        for(Square to = from+9; ((to%8) != 0 && to<64); to+=9) Direction[from][to] = 9;
        for(Square to = from-7; (((to%8) != 0) && to>-1); to-=7) Direction[from][to] = 7;

        for(Square to = from-1; ((to+1)%8) != 0; to--) Direction[from][to] = 1;
        for(Square to = from-9; (((to+1)%8) != 0 && to>-1); to-=9) Direction[from][to] = 9;
        for(Square to = from+7; (((to+1)%8) != 0 && to < 64); to+=7) Direction[from][to] = 7;
    }
}
